package org.yray.tts.dic;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class StopWordDict {
    private static Set<String> stopWordsSet=new HashSet<>();

    static {
         loadStopWords();
    }

    private static void loadStopWords( ){
        BufferedReader bufr;
        try
        {
            InputStream in= StopWordDict.class.getResourceAsStream("/stop_words.txt");
            bufr = new BufferedReader(new InputStreamReader(in));
            String line=null;
            while((line=bufr.readLine())!=null) {
                stopWordsSet.add(line.trim());
            }
            try
            {
                bufr.close();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static List<String> removeStopWord(List<String> tokens )
    {
      return   tokens.stream().filter((v)->!stopWordsSet.contains(v)
        ).collect(Collectors.toList());
    }

}
